﻿module Sustainalytics.EsgRatings {

    export class EsgRpIndicatorService implements IEsgRpIndicatorService {

        constructor(
            private $q: ng.IQService,
            private $http: ng.IHttpService) {
        }

        public get(companyId: string, clusterName?: string, theme?: EsgThemeEnum, skip?: number, take?: number): ng.IPromise<EsgRpIndicatorDto[]> {
            var ctx = this;

            var def = ctx.$q.defer();

            var params = $.param(
                {
                    clusterName: clusterName,
                    theme: theme,
                    skip: skip,
                    take: take
                });

            var url = '/esgratingserv/api/v1/company/' + companyId + '/esgRpIndicator?' + params;
            var promise = ctx.$http.get(url).then(
                // success
                function (res: ng.IHttpPromiseCallbackArg<EsgRpIndicatorDto>) {
                    def.resolve(res.data);
                },
                // error
                function (res: ng.IHttpPromiseCallbackArg<EsgRpIndicatorDto>) {
                    def.reject(res);
                });

            return def.promise;
        }
    }


    export var esgRpIndicatorServiceName = 'EsgRpIndicatorService';

    angular.module(esgRatingsModuleName).service(esgRpIndicatorServiceName, EsgRpIndicatorService);
} 